import { showModal, showToast } from "../../utils/asyncWx";
import { getCollectInfo,deleteCollectOne} from "../../api/collect.js";
Page({

    data: {
        userid:null,
        collect: [],
        tabs: [{
                id: 0,
                value: "商品收藏",
                isActive: true
            },
            {
                id: 1,
                value: "品牌收藏",
                isActive: false
            },
            {
                id: 2,
                value: "店铺收藏",
                isActive: false
            },
            {
                id: 3,
                value: "浏览足迹",
                isActive: false
            },
        ],

    },

    async getCollectInfo(){
        const collectall = await getCollectInfo(this.data.userid)
      console.log(collectall);
        this.setData({
            collect:collectall
        })
    },

    handleTabsItemChange(e) {
        const { index } = e.detail;
        let { tabs } = this.data;
        tabs.forEach((v, i) => i === index ? v.isActive = true : v.isActive = false);
        this.setData({
            tabs
        })
    },



   async handleDelete(e) {
        var { set } = e.currentTarget.dataset;
        var collect = this.data.collect;
        const result2 = await deleteCollectOne(this.data.userid,set)
         wx.showToast({
            title: '取消成功',
            icon: 'success',
            mask: true,
        });
        this.getCollectInfo()
    },

    onShow() {
        let userid= wx.getStorageSync('userid')
        if(!userid){
            wx.switchTab({
                url: '/pages/user/index',
            })
             showToast({ title: "请先登录" });
        }else{
            this.setData({
                userid
               })
                this.getCollectInfo()
        }
    }
})